p1 = 1 * 1e-3;

//donnees geometriques

pi      = 3.1415;
mm      = 1e-3;
k       = 1.5;
bl      = 100 * mm;
bk      = k * bl;
c       = 30 * mm;
din     = 200 * mm;
largint = din - bl;
largext = din + bl;
largt   = 500 * mm;
longt   = 600 * mm;
long    = largt + 2 * c;
c2      = 2 * mm ;

x1       = ((largext/2.)^2 -(bk-c)^2)^.5;
x2       = long/2.-bk-largint/2.;
x3       = ((largext/2.)^2 -(bk-c2)^2)^.5;

h1 = 0 * mm;
h2 = 1 * mm;
h3 =  25* mm;
h4 = 35 * mm;
h5 = 130 * mm;

/* generation des differentes couches d'elements et maillage des surfaces */

/* COUCHE 1 */

Point(1000001) = { -largint/4 , 0 , h1 , p1 };
Point(1000002) = {  largint/4 , 0 , h1 , p1 };
Point(1000003) = { -largint/4 , x2/2. , h1 , p1 };
Point(1000004) = {  largint/4 , x2/2. , h1 , p1 };
Point(1000005) = { -largint/2. , 0 , h1 , p1 };
Point(1000006) = { largint/2. , 0 , h1 , p1 };
Point(1000007) = { -largint/2.+.0000001 , x2+.0000001 , h1 , p1 };
Point(1000008) = { largint/2.+.0000001 , x2 , h1 , p1 };
Point(1000009) = { 0   , x2 , h1 , p1 };
Point(1000010) = { -largint/2. + largint/2*Sin(Pi/6), x2+ largint/2*Cos(Pi/6) , h1 , p1 };
Point(1000011) = { largint/2.-  largint/2*Sin(Pi/6) , x2+largint/2*Cos(Pi/6)  , h1 ,  p1 };
Point(1000012) = { -largext/2. , 0 , h1 , p1 };
Point(1000013) = {  largext/2. , 0 , h1 , p1 };
Point(1000014) = { -largext/2. , long/2. - bk , h1 , p1 };
Point(1000015) = {  largext/2. , long/2. - bk , h1 , p1 };
Point(1000016) = {  -x1        , long/2-c , h1 , p1 };
Point(1000017) = {   x1        , long/2-c , h1 , p1 };
Point(1000018) = {  -x3        , long/2-c2 , h1 , p1 };
Point(1000019) = {   x3        , long/2-c2 , h1 , p1 };
Point(1000022) = { 0 , long/2. - bk , h1 , p1 };
Point(1000023) = {  largint/8 , x2/2 , h1 , p1 };
Point(1000024) = { -largint/8 , x2/2. , h1 , p1 };
Point(1000025) = {  largint/8 , 0 , h1 , p1 };
Point(1000026) = { -largint/8 , 0 , h1 , p1 };
Point(1000027) = { -longt/2.  , 0 , h1 , p1 };
Point(1000028) = { longt/2.   , 0 , h1 , p1 };
Point(1000029) = { -longt/2.  , largt/2. , h1 , p1 };
Point(1000030) = { longt/2.   , largt/2. , h1 , p1 };
mult1         =1.5;
Point(1000031) = { -longt/2.  , largt/2.* mult1 , h1 , p1 };
Point(1000032) = { longt/2.   , largt/2.* mult1 , h1 , p1 };
Point(1000033) = { -longt/2.  , largt/4. , h1 , p1 };
Point(1000034) = { longt/2.   , largt/4. , h1 , p1 };

Line(1000101) = {1000002,1000004};

Line(1000103) = {1000003,1000001};
Line(1000104) = {1000002,1000006};
Line(1000105) = {1000006,1000008};
Line(1000106) = {1000007,1000005};
Line(1000107) = {1000005,1000001};
Line(1000108) = {1000006,1000013};
Line(1000109) = {1000012,1000005};
Line(1000110) = {1000013,1000015};
Line(1000111) = {1000015,1000008};
Line(1000112) = {1000007,1000014};
Line(1000113) = {1000014,1000012};
Circle(1000114) = {1000008,1000009,1000011};
Circle(1000115) = {1000011,1000009,1000010};
Circle(1000116) = {1000010,1000009,1000007};

Line(1000117) = {1000016,1000017};
Circle(1000118) = {1000015,1000022,1000017};
Circle(1000119) = {1000016,1000022,1000014};
Line(1000120) = {1000011,1000017};
Line(1000121) = {1000010,1000016};
Line(1000122) = {1000018,1000019};
Circle(1000123) = {1000017,1000022,1000019};
Circle(1000124) = {1000018,1000022,1000016};
Line(1000125) = {1000003,1000024};
Line(1000126) = {1000024,1000023};
Line(1000127) = {1000023,1000004};
Line(1000128) = {1000004,1000008};
Line(1000129) = {1000023,1000011};
Line(1000130) = {1000024,1000010};
Line(1000131) = {1000003,1000007};
Line(1000132) = {1000001,1000026};
Line(1000133) = {1000026,1000025};
Line(1000134) = {1000025,1000002};
Line(1000135) = {1000025,1000023};
Line(1000136) = {1000026,1000024};
Line Loop(1000137) = {1000128,-1000105,-1000104,1000101};
Plane Surface(1000138) = {1000137};
Line Loop(1000139) = {1000101,-1000127,-1000135,1000134};
Plane Surface(1000140) = {1000139};
Line Loop(1000141) = {1000135,-1000126,-1000136,1000133};
Plane Surface(1000142) = {1000141};
Line Loop(1000143) = {1000136,-1000125,1000103,1000132};
Plane Surface(1000144) = {1000143};
Line Loop(1000145) = {1000107,-1000103,1000131,1000106};
Plane Surface(1000146) = {1000145};
Line Loop(1000147) = {-1000131,1000125,1000130,1000116};
Plane Surface(1000148) = {1000147};
Line Loop(1000149) = {-1000130,1000126,1000129,1000115};
Plane Surface(1000150) = {1000149};
Line Loop(1000151) = {-1000114,-1000128,-1000127,1000129};
Plane Surface(1000152) = {1000151};
Line Loop(1000153) = {-1000111,-1000110,-1000108,1000105};
Plane Surface(1000154) = {1000153};
Line Loop(1000155) = {-1000118,1000111,1000114,1000120};
Plane Surface(1000156) = {1000155};
Line Loop(1000157) = {1000117,-1000120,1000115,1000121};
Plane Surface(1000158) = {1000157};
Line Loop(1000159) = {1000117,1000123,-1000122,1000124};
Plane Surface(1000160) = {1000159};
Line Loop(1000161) = {1000112,-1000119,-1000121,1000116};
Plane Surface(1000162) = {1000161};
Line Loop(1000163) = {-1000109,-1000113,-1000112,1000106};
Plane Surface(1000164) = {1000163};

Line(1000165) = {1000012,1000027};
Line(1000166) = {1000027,1000033};
Line(1000167) = {1000033,1000029};
Line(1000168) = {1000029,1000016};
Line(1000169) = {1000029,1000031};
Line(1000170) = {1000031,1000032};
Line(1000171) = {1000032,1000030};
Line(1000172) = {1000030,1000034};
Line(1000173) = {1000034,1000028};
Line(1000174) = {1000028,1000013};
Line(1000175) = {1000015,1000034};
Line(1000176) = {1000017,1000030};
Line(1000177) = {1000019,1000032};
Line(1000178) = {1000018,1000031};
Line(1000179) = {1000014,1000033};


Line Loop(1000180) = {1000175,1000173,1000174,1000110};
Plane Surface(1000181) = {1000180};
Line Loop(1000182) = {1000176,1000172,-1000175,1000118};
Plane Surface(1000183) = {1000182};
Line Loop(1000184) = {1000171,-1000176,1000123,1000177};
Plane Surface(1000185) = {1000184};
Line Loop(1000186) = {1000170,-1000177,-1000122,1000178};
Plane Surface(1000187) = {1000186};
Line Loop(1000188) = {-1000168,1000169,-1000178,1000124};
Plane Surface(1000189) = {1000188};
Line Loop(1000190) = {1000179,1000167,1000168,1000119};
Plane Surface(1000191) = {1000190};
Line Loop(1000192) = {1000165,1000166,-1000179,1000113};
Plane Surface(1000193) = {1000192};

nbext=6;
pwext=1.;
nbind=10 ;
pwind=2.;

Transfinite Line{1000118,1000114,1000127,1000134,1000110,1000105,1000101,1000135,1000113,1000106,1000103,1000136,1000119,1000116,1000125,1000133,1000132,1000126,1000115,1000117,1000122,1000170,1000172,1000167,1000173,1000166} = 9 Using Power 1.0;
Transfinite Line{1000104,1000128,1000129,1000130,1000131,1000107} = 5 Using Power 1.0;
Transfinite Line{1000108,-1000111,1000120,1000121,1000112,-1000109} =nbind Using Power pwind;
Transfinite Line{1000123,1000124,1000171,1000169} = 6 Using Power 1.0;
Transfinite Line{1000174,1000175,1000176,1000177,1000178,1000168,1000179,1000165} = nbext Using Power pwext;

ss[] = {1000154,1000160,1000158,1000150,1000142,1000140,1000144,1000146,1000158,
        1000156,1000152,1000164,1000162,1000148,1000138,1000181,1000183,1000187,
        1000191,1000193,1000185,1000189};

Transfinite Surface{ss[]};
Recombine Surface{ss[]};


For i In {0:#ss[]-1}
  Extrude  {0,0,h5} { Surface {ss[i]}; Layers{{1,1,1,1},{h2/h5,h3/h5,h4/h5,1}}; Recombine; }
EndFor
